import SubscriptionDetail from '../../common/subscription-detail/subscription-detail.vue'
import { getSubscriptionList, showMsg } from '../../../../../vuex/action.js'

export default {
  name: 'InvesterSubscription',
  data() {
    return {
      pages: {
        start: 0,
        limit: 20
      },
      subscriptionList: []
    }
  },
  computed: {
    betaId() {
      return this.$route.params.id || ''
    },
    subType() {
      return this.$route.query.subType || ''
    }
  },
  methods: {
    evtGoHistory() {
      window.history.back()
    },
    getSubscriptionList() {
      let params = {
        id: this.betaId,
        type: this.payType,
        start: this.pages.start,
        limit: this.pages.limit
      }
      if (this.subType) {
        params = Object.assign(params, { subType: this.subType })
      }
      this.xGetSubscriptionList(params).then((res) => {
        this.subscriptionList = res.data.statistics
      }).catch((res) => {
        this.xShowMsg({
          type: 'danger',
          content: res.error_msg
        })
      })
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetSubscriptionList: getSubscriptionList
    },
    getters: {
      payType: state => state.payType
    }
  },
  components: {
    'subscription-detail': SubscriptionDetail
  },
  ready() {
    this.getSubscriptionList()
  }
}
